<template>
  <div class="home">
    <Nav :showLeft="false" mytitle="wj记事本" />
    <ul class="list_box">
      <li v-for="item in list" :key="item.id">
        <div class="left_content_box" @click="goInfo(item.id)">
          <h4>{{ item.title }}</h4>
          <p>{{ item.time }}</p>
        </div>
        <div
          class="right_icon_box iconfont icon-close"
          @click="del(item.id)"
        ></div>
      </li>
    </ul>
    <!-- 点击跳转到Info页面 -->
    <div class="newBtn" @click="go">
      <span class="iconfont icon-add"></span>
      新建
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import Nav from "../components/Nav.vue";

export default {
  name: "Home",
  computed: {
    list() {
      return this.$store.state.list;
    },
  },
  components: {
    Nav,
  },
  methods: {
    go() {
      this.$router.push("/info");
    },
    goInfo(id) {
      this.$router.push({ path: "/info", query: { _id: id } });
    },
    del(id) {
      this.$store.commit("removeNote", id);
    },
  },
};
</script>
<style lang='less'>
.list_box {
  list-style: none;
  li {
    width: 100%;
    text-align: left;
    padding: 0.4rem 0.3rem;
    box-sizing: border-box;
    font-size: 0.5rem;
    border-bottom: 1px solid #eee;
    display: flex;
    .right_icon_box {
      width: 1rem;
      font-size: 0.8rem;
      color: rgb(230, 211, 45);
    }
    .left_content_box {
      flex: auto;
      p {
        font-size: 0.4rem;
      }
    }
  }
}
.newBtn {
  position: fixed;
  bottom: 1rem;
  width: 2.6rem;
  height: 1.2rem;
  line-height: 1.2rem;
  left: 50%;
  margin-left: -1.3rem;
  border: 1px solid #ccc;
  border-radius: 0.5rem;
  font-size: 0.5rem;
  box-shadow: 0px 3px 7px 2px #ccc;
}
</style>
